<div data-hook="admin_shipping_method_form_fields">
  <div class="row">
    <div data-hook="admin_shipping_method_form_name_field" class="col-md-6">
      <%= f.field_container :name, class: ['form-group'] do %>
        <%= f.label :name, Spree.t(:name) %>
        <%= f.text_field :name, class: 'form-control' %>
        <%= f.error_message_on :name %>
      <% end %>
    </div>

    <div data-hook="admin_shipping_method_form_display_field" class="col-md-6">
      <%= f.field_container :display_on, class: ['form-group'] do %>
        <%= f.label :display_on, Spree.t(:display) %>
        <%= select(:shipping_method, :display_on, Spree::ShippingMethod::DISPLAY.collect { |display| [Spree.t(display), display == :both ? nil : display.to_s] }, {}, { class: 'select2' }) %>
        <%= f.error_message_on :display_on %>
      <% end %>
    </div>
  </div>

  <div class="row">
    <div data-hook="admin_shipping_method_form_internal_name_field" class="col-md-4">
      <%= f.field_container :admin_name, class: ['form-group'] do %>
        <%= f.label :admin_name, Spree.t(:internal_name) %>
        <%= f.text_field :admin_name, class: 'form-control', label: false %>
        <%= f.error_message_on :admin_name %>
      <% end %>
    </div>

    <div data-hook="admin_shipping_method_form_code" class="col-md-4">
      <%= f.field_container :code, class: ['form-group'] do %>
        <%= f.label :code, Spree.t(:code) %>
        <%= f.text_field :code, class: 'form-control', label: false %>
        <%= f.error_message_on :code %>
      <% end %>
    </div>

    <div data-hook="admin_shipping_method_form_tracking_url_field" class="col-md-4">
      <%= f.field_container :tracking_url, class: ['form-group'] do %>
        <%= f.label :tracking_url, Spree.t(:tracking_url) %>
        <%= f.text_field :tracking_url, class: 'form-control', placeholder: Spree.t(:tracking_url_placeholder) %>
        <%= f.error_message_on :tracking_url %>
      <% end %>
    </div>
  </div>
</div>

<div class="row">
  <div data-hook="admin_shipping_method_form_availability_fields" class="col-md-6">
    <div class="panel panel-default categories">
      <div class="panel-heading">
        <h1 class="panel-title">
          <%= Spree.t(:shipping_categories) %>
        </h1>
      </div>

      <div class="panel-body">
        <%= f.field_container :categories, class: ['form-group'] do %>
          <% Spree::ShippingCategory.all.each do |category| %>
            <div class="checkbox">
              <%= label_tag do %>
                <%= check_box_tag('shipping_method[shipping_categories][]', category.id, @shipping_method.shipping_categories.include?(category)) %>
                <%= category.name %>
              <% end %>
            </div>
          <% end %>
          <%= f.error_message_on :shipping_category_id %>
        <% end %>
      </div>
    </div>
  </div>

  <div class="col-md-6">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h1 class="panel-title">
          <%= Spree.t(:zones) %>
        </h1>
      </div>

      <div class="panel-body">
        <%= f.field_container :zones, class: ['form-group'] do %>
          <% shipping_method_zones = @shipping_method.zones.to_a %>
          <% Spree::Zone.all.each do |zone| %>
            <div class="checkbox">
              <%= label_tag do %>
                <%= check_box_tag('shipping_method[zones][]', zone.id, shipping_method_zones.include?(zone)) %>
                <%= zone.name %>
              <% end %>
            </div>
          <% end %>
          <%= f.error_message_on :zone_id %>
        <% end %>
      </div>
    </div>
  </div>
</div>

<div class="row">
  <div data-hook="admin_shipping_method_form_calculator_fields" class="col-md-6">
    <%= render partial: 'spree/admin/shared/calculator_fields', locals: { f: f } %>
  </div>

  <div class="col-md-6">
    <div class="panel panel-default tax_categories">
      <div class="panel-heading">
        <h1 class="panel-title">
          <%= Spree.t(:tax_category) %>
        </h1>
      </div>

      <div class="panel-body">
        <%= f.field_container :categories, class: ['form-group'] do %>
          <%= f.select :tax_category_id, @tax_categories.map { |tc| [tc.name, tc.id] }, { include_blank: true }, class: "select2" %>
          <%= f.error_message_on :tax_category_id %>
        <% end %>
      </div>
    </div>
  </div>
</div>
